package info.sean.main;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class TestM {

    public static void main(String[] args) {
        for (int i = 10; i <= 15; i++) {
            if (i == 15){
                break;
            }
            System.out.println(i);
        }

        List<BigDecimal> invoices = new LinkedList<>();
        invoices.add(BigDecimal.valueOf(9.9));
        invoices.add(BigDecimal.valueOf(1.0));
        invoices.add(BigDecimal.valueOf(19.99));
        invoices.add(BigDecimal.valueOf(0.2));
        invoices.add(BigDecimal.valueOf(5.5));
        System.out.println("invoices = " + invoices);
        // sum using a for loop
        BigDecimal sum = BigDecimal.ZERO;
        for (BigDecimal amt : invoices) {
            sum = sum.add(amt);
        }
        System.out.println("Sum = " + sum);

        // sum using stream
        BigDecimal sum2 = invoices.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
        System.out.println("Sum (Stream) = " + sum2);

        System.out.println("\"------------------------------------\" = "+"\r\n" + "------------------------------------");


        AtomicInteger sendcount = new AtomicInteger(0);
        for (int i = 0; i <= 15; i++) {
            sendcount.getAndIncrement();
        }
        for (int i = 16; i < 30; i++) {
            sendcount.getAndIncrement();
        }
        int andIncrement = sendcount.get();
        System.out.println("andIncrement = " + andIncrement);
    }

}
